<template>
  <div class="batch-param">
    <el-tabs class="tabs" v-model="activeName" @tab-click="handleClick">
      <el-tab-pane
        label="柜参数"
        name="first"
        v-if="currentRow.type == 'PARAM_WRITE'"
      >
        <el-form
          class="boxForm"
          ref="boxForm"
          :model="boxForm"
          label-width="150px" size="small"
          element-loading-background="rgba(0, 0, 0, 0.08)"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
        >
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox v-model="checkList.check1" v-if="!isShow" @change="switchChecked('06010014', '0')">
            </el-checkbox>
            <el-form-item label="快充">
              <el-switch
                :disabled="!checkList.check1"
                v-model="boxForm['06010014']"
                active-value="1" inactive-value="0"
              >
              </el-switch>
              <span v-if="isShow">
                <span class="forbidden" v-if="boxForm['06010014'] == '0'"
                  >禁用</span
                >
                <span class="enable" v-else-if="boxForm['06010014'] == '1'"
                  >启用</span
                >
                <span class="forbidden" v-else
                  >{{boxForm['06010014']}}</span
                >
              </span>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check2"
              v-if="!isShow" @change="switchChecked('06010015', '0')"
            ></el-checkbox>
            <el-form-item label="备电">
              <el-switch
                :disabled="!checkList.check2"
                v-model="boxForm['06010015']"
                active-value="1" inactive-value="0"
              >
              </el-switch>
              <span v-if="isShow">
                <span class="forbidden" v-if="boxForm['06010015'] == '0'"
                  >禁用</span
                >
                <span class="enable" v-else-if="boxForm['06010015'] == '1'"
                  >启用</span
                >
                <span class="forbidden" v-else
                  >{{boxForm['06010015']}}</span
                >
              </span>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check3"
              v-if="!isShow" @change="switchChecked('06010023', '0')"
            ></el-checkbox>
            <el-form-item label="整流单元休眠">
              <el-switch
                :disabled="!checkList.check3"
                v-model="boxForm['06010023']"
                active-value="1" inactive-value="0"
              >
              </el-switch>
              <span v-if="isShow">
                <span class="forbidden" v-if="boxForm['06010023'] == '0'"
                  >禁用</span
                >
                <span class="enable" v-else-if="boxForm['06010023'] == '1'"
                  >启用</span
                >
                <span class="forbidden" v-else
                  >{{boxForm['06010023']}}</span
                >
              </span>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check4"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="电子锁反馈类型">
              <el-select clearable class="input-width"
                :disabled="!checkList.check4"
                v-model="boxForm['06010007']"
                placeholder="请选择电子锁反馈类型"
              >
                <el-option
                  v-for="item in getLockOption"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check5"
              v-if="!isShow" @change="switchChecked('06030007', '2')"
            ></el-checkbox>
            <el-form-item label="远程控制">
              <!-- 1：开启 2：关闭 -->
              <el-switch
                :disabled="!checkList.check5"
                v-model="boxForm['06030007']"
                active-value="1" inactive-value="2"
              >
              </el-switch>
              <span v-if="isShow">
                <span class="enable" v-if="boxForm['06030007'] == '1'"
                  >开启</span
                >
                <span class="forbidden" v-else-if="boxForm['06030007'] == '2'"
                  >关闭</span
                >
                <span class="forbidden" v-else
                  >{{boxForm['06030007']}}</span
                >
                </span
              >
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check6"
              v-if="!isShow" @change="switchChecked('06010008', '0')"
            ></el-checkbox>
            <el-form-item label="门轴" style="width: 100%">
              <el-select clearable  class="input-width"
                :disabled="boxForm['06010008'] != 1 || !checkList.check6"
                v-model="boxForm['06010009']"
                placeholder="请选择门轴"
              >
                <el-option
                  v-for="item in getLockOption"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
              <el-tooltip
                :content="`门轴使能：${
                  boxForm['06010008'] == 1 ? '使能' : '禁用'
                }`"
                placement="top"
                style="margin-left: 20px"
              >
                <el-switch
                  :disabled="!checkList.check6"
                  v-model="boxForm['06010008']"
                  active-value="1" inactive-value="0"
                >
                </el-switch>
              </el-tooltip>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check7"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="电池在位模式">
              <el-select clearable class="input-width"
                :disabled="!checkList.check7"
                v-model="boxForm['06010011']"
                placeholder="请选择电池在位模式"
              >
                <el-option
                  v-for="item in batteryIsOn"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check8"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="灭火器反馈类型">
              <el-select clearable class="input-width"
                :disabled="!checkList.check8"
                v-model="boxForm['06010022']"
                placeholder="请选择灭火器反馈类型"
              >
                <el-option
                  v-for="item in getLockOption"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check9"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="主控2.0/3.0版本">
              <el-select clearable class="input-width"
                :disabled="!checkList.check9"
                v-model="boxForm['06010006']"
                placeholder="请选择主控2.0/3.0版本"
              >
                <el-option
                  v-for="item in mainControlVersion"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check10"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="消防模式">
              <el-select clearable class="input-width"
                :disabled="!checkList.check10"
                v-model="boxForm['06010024']"
                placeholder="请选择消防模式"
              >
                <el-option
                  v-for="item in getLockOption"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check11"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="系统启动散热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check11"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010016']"
                placeholder="系统启动散热温度"
                :min="0"
                :max="80"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check12"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="系统停止散热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check12"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010017']"
                placeholder="系统停止散热温度"
                :min="0"
                :max="80"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check13"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="启动整柜加热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check13"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010018']"
                placeholder="启动整柜加热温度"
                :min="0"
                :max="50"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check14"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="停止整柜加热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check14"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010019']"
                placeholder="停止整柜加热温度"
                :min="0"
                :max="50"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check15"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="有序充电">
              <el-input clearable class="input-width"
                :disabled="!checkList.check15"
                v-model="boxForm['06010027']"
                placeholder="请输入有序充电"
              ></el-input>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check16"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="启动单仓加热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check16"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010020']"
                placeholder="启动单仓加热温度"
                :min="0"
                :max="50"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check17"
              v-if="!isShow" @change="switchChecked('06010028', '0')"
            ></el-checkbox>
            <el-form-item label="电池容量区分">
              <el-switch
                :disabled="!checkList.check17"
                v-model="boxForm['06010028']"
                active-value="1" inactive-value="0"
                @change="switchChange($event, '06010028', '0')"
              >
              </el-switch>
              <span v-if="isShow">
                <span class="enable" v-if="boxForm['06010028'] == '1'"
                  >开启</span
                >
                <span class="forbidden" v-else-if="boxForm['06010028'] == '0'"
                  >禁用</span
                >
                <span class="forbidden" v-else
                  >{{boxForm['06010028']}}</span
                >
                </span
              >
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check18"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="停止单仓加热温度(℃)">
              <el-input-number class="input-width"
                :disabled="!checkList.check18"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010021']"
                placeholder="停止单仓加热温度"
                :min="0"
                :max="50"
              ></el-input-number>
            </el-form-item>
          </div>
          <!-- <div class="single">
            <el-checkbox
              v-model="checkList.check19"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="邮政密码">
              <el-input
                :disabled="!checkList.check19"
                v-model="boxForm['06010029']"
                placeholder="请输入邮政密码"
              ></el-input>
            </el-form-item>
          </div> -->
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check19"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="满电阈值(%)">
              <el-input-number class="input-width"
                :disabled="!checkList.check19"
                :step="1"
                :precision="0"
                controls-position="right"
                v-model="boxForm['06010031']"
                placeholder="请输入满电阈值"
                :min="1"
                :max="100"
              ></el-input-number>
            </el-form-item>
          </div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
            <el-checkbox
              v-model="checkList.check20"
              v-if="!isShow"
            ></el-checkbox>
            <el-form-item label="管理员密码">
              <el-input clearable class="input-width"
                :disabled="!checkList.check20"
                v-model.trim="boxForm['06010030']" @input="boxForm['06010030'] = boxForm['06010030'].replace(/[\u4E00-\u9FA5]/g,'')"
                placeholder="请输入管理员密码"
              ></el-input>
            </el-form-item>
          </div>
          <el-card class="rules" style="width: 100%" v-if="!isShow">
            <el-form-item label="个数">
              <el-input-number
                :min="1" class="input-width"
                :max="50"
                :step="1"
                step-strictly
                controls-position="right"
                placeholder="请输入个数"
                v-model="operateRule.count"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="间隔(分钟)">
              <el-input-number
                :min="1" class="input-width"
                :max="60"
                :step="1"
                step-strictly
                controls-position="right"
                placeholder="请输入间隔"
                v-model="operateRule.interval"
              >
              </el-input-number>
            </el-form-item>
          </el-card>
        </el-form>

        <el-form
          ref="binForm"
          class="binForm boxForm"
          :model="binForm"
          label-width="150px"
          v-if="isShow" size="small"
        >
        <div class="single" :style="{width:!isShow?'33%':'46%'}">
          <el-form-item label="运行模式">
            <el-select class="input-width"
              v-model="binForm['06010044']"
              placeholder="请选择运行模式"
              disabled
            >
              <el-option
                v-for="item in runState"
                :disabled="item.readonly"
                :key="item.code"
                :label="item.label"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>  
        <div class="single" :style="{width:!isShow?'33%':'46%'}">
          <el-form-item label="备电模式">
            <el-select class="input-width"
              v-model="binForm['06010045']"
              placeholder="请选择备电模式"
              disabled
            >
              <el-option
                v-for="item in electricMode"
                :key="item.code"
                :label="item.label"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="single" :style="{width:!isShow?'33%':'46%'}">
          <el-form-item label="充电电压">
            <el-input class="input-width"
              v-model="binForm['06010046']"
              placeholder="请输入充电电压"
              disabled
            ></el-input>
          </el-form-item></div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
          <el-form-item label="充电电流">
            <el-select class="input-width"
              v-model="binForm['06010047']"
              placeholder="请选择充电电流"
              disabled
            >
              <el-option
                v-for="item in electricJuice"
                :key="item.code"
                :label="item.label"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item></div>
          <div class="single" :style="{width:!isShow?'33%':'46%'}">
          <el-form-item label="电池类型">
            <el-select class="input-width"
              v-model="binForm['06010048']"
              placeholder="请选择电池类型"
              disabled
            >
              <el-option
                v-for="item in batteryType"
                :key="item.code"
                :label="item.label"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item></div>
        </el-form>
      </el-tab-pane>
      <el-tab-pane
        label="运营平台链接参数"
        name="fourth"
        v-if="currentRow.type == 'CONTROL_CONNECTION_PARAM'"
      >
        <el-form
          class="boxForm operateForm"
          ref="operateForm"
          :rules="operateFormRules"
          :model="operateForm"
          label-width="100px" size="small"
          element-loading-background="rgba(0, 0, 0, 0.08)"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
        >
          <el-form-item label="服务地址" prop="url">
            <el-input clearable
              :disabled="isShow"
              v-model="operateForm.url"
              placeholder="请输入服务地址"
            ></el-input>
          </el-form-item>
          <el-form-item label="端口" prop="port">
            <el-input clearable
              :disabled="isShow"
              v-model="operateForm.port"
              placeholder="请输入端口"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户名" prop="username">
            <el-input clearable
              :disabled="isShow"
              v-model="operateForm.username"
              placeholder="请输入用户名"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input clearable
              :disabled="isShow"
              v-model.trim="operateForm.password" @input="operateForm.password = operateForm.password.replace(/[\u4E00-\u9FA5]/g,'')"
              placeholder="请输入密码"
            ></el-input>
          </el-form-item>
          <el-form-item label="产品密钥" prop="productKey">
            <el-input clearable
              :disabled="isShow"
              v-model.trim="operateForm.productKey" @input="operateForm.productKey = operateForm.productKey.replace(/[\u4E00-\u9FA5]/g,'')"
              placeholder="请输入产品密钥"
            ></el-input>
          </el-form-item>
          <el-form-item label="设备名称" prop="deviceName">
            <el-input clearable
              :disabled="isShow"
              v-model="operateForm.deviceName"
              placeholder="请输入设备名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="设备密钥" prop="deviceSecret">
            <el-input clearable
              :disabled="isShow"
              v-model.trim="operateForm.deviceSecret" @input="operateForm.deviceSecret = operateForm.deviceSecret.replace(/[\u4E00-\u9FA5]/g,'')"
              placeholder="请输入设备密钥"
            ></el-input>
          </el-form-item>
          <el-card style="width: 100%" class="rules" v-if="!isShow">
            <el-form-item label="个数" prop="count">
              <el-input-number
                :min="1" class="input-width"
                :max="50"
                :step="1"
                step-strictly
                controls-position="right"
                placeholder="请输入个数"
                v-model="operateForm.count"
              ></el-input-number>
            </el-form-item>
            <el-form-item label="间隔(分钟)" style="width: 40%" prop="interval">
              <el-input-number
                :min="1" class="input-width"
                :max="60"
                :step="1"
                step-strictly
                controls-position="right"
                placeholder="请输入间隔"
                v-model="operateForm.interval"
              >
              </el-input-number>
            </el-form-item>
          </el-card>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <div class="tip-btn" v-if="!isShow">
      <el-link type="danger" v-if="activeName == 'first'"
        >请勾选需要设置的参数</el-link
      >
      <el-button
        type="primary"
        size="small"
        class="batch_btn"
        @click="isBatchSetting"
        >批量设置</el-button
      >
    </div>
  </div>
</template>

<script>
import {
  getLockOption,
  batteryIsOn,
  mainControlVersion,
  runState,
  electricMode,
  electricJuice,
  batteryType,
} from "@/utils/config";
import { handleConfirm } from "@/utils/messageBox";
import { equipment } from "@/api/factuer";

import { mapGetters} from "vuex";

export default {
  props: {
    batchSearchForm: {
      type: Object,
    },
    currentRow: {
      type: Object,
      default: () => {},
    },
    equipTableData: {
      type: Array,
      default: () => [],
    },
    currentParam: {
      type: null,
      default: () => null,
    },
    isShow: {
      //纯展示 不可操作
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      getLockOption: getLockOption,
      batteryIsOn: batteryIsOn,
      mainControlVersion: mainControlVersion,
      runState: runState,
      electricMode: electricMode,
      electricJuice: electricJuice,
      batteryType: batteryType,
      //   柜参数
      boxForm: {
        "06010014": undefined,
        "06010015": undefined,
        "06010023": undefined,
        "06010007": undefined,
        "06030007": undefined,
        "06010009": undefined,
        "06010011": undefined,
        "06010022": undefined,
        "06010006": undefined,
        "06010024": undefined,
        "06010016": undefined,
        "06010017": undefined,
        "06010018": undefined,
        "06010019": undefined,
        "06010027": undefined,
        "06010020": undefined,
        "06010028": undefined,
        "06010021": undefined,
        // "06010029": undefined,
        "06010031": undefined,
        "06010030": undefined,
        "06010008": undefined,
      },
      checkList: {
        check1: false,
        check2: false,
        check3: false,
        check4: false,
        check5: false,
        check6: false,
        check7: false,
        check8: false,
        check9: false,
        check10: false,
        check11: false,
        check12: false,
        check13: false,
        check14: false,
        check15: false,
        check16: false,
        check17: false,
        check18: false,
        check19: false,
        check20: false,
      },
      binForm: {
        "06010044": undefined,
        "06010045": undefined,
        "06010046": undefined,
        "06010047": undefined,
        "06010048": undefined,
      },
      activeName: "first",
      operateForm: {
        deviceName: "",
        deviceSecret: "",
        password: "",
        port: "",
        productKey: "",
        url: "",
        username: "",
        count: 30,
        interval: 1,
      },
      operateFormRules: {
        deviceName: [
          { required: true, message: "请输入设备名称", trigger: "blur" },
        ],
        deviceSecret: [
          { required: true, message: "请输入设备密钥", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        port: [{ required: true, message: "请输入端口", trigger: "blur" }],
        productKey: [
          { required: true, message: "请输入产品密钥", trigger: "blur" },
        ],
        url: [{ required: true, message: "请输入服务地址", trigger: "blur" }],
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        interval: [{ required: true, message: "请输入间隔", trigger: "blur" }],
        count: [{ required: true, message: "请输入个数", trigger: "blur" }],
      },
      operateRule: {
        interval: 1,
        count: 30,
      },
    };
  },
  computed: {
        ...mapGetters(["equipTypeCode"]),
  },
  watch: {
    "currentRow.type": {
      handler(val) {
        if (val == "CONTROL_CONNECTION_PARAM") {
          this.activeName = "fourth";
        } else {
          this.activeName = "first";
        }
      },
      deep: true, //对象内部的属性监听，也叫深度监听
      immediate: true,
    },
    currentParam: {
      handler(val) {
        if (this.isShow) {
          this.resetOperateData();
          this.resetData();
          if (Array.isArray(val)) {
            val.forEach((item) => {
              for (const key in this.boxForm) {
                if (item.id == key) {
                  this.boxForm[key] = item.value;
                }
              }
            });
            for (const key in this.binForm) {
              val.forEach((item) => {
                if (key == item.id) {
                  this.binForm[key] = item.value;
                }
              });
            }
          } else {
            this.operateForm = { ...val };
          }
          
        }
      },
      deep: true, //对象内部的属性监听，也叫深度监听
      immediate: true,
    },
  },
  created() {},
  methods: {
    switchChecked(param, val) {
      this.boxForm[param] = this.boxForm[param] ? this.boxForm[param] : val;
    },
    handleClick(tab, event) {
      this.activeName = tab.name;
    },
    isBatchSetting() {
      if (this.equipTableData.length == 0) {
        this.$message.error("暂无符合条件的设备！");
        return;
      }
      let isChecked = {};
      Object.values(this.checkList).map((item, index) => {
        Object.keys(this.boxForm).filter((pp, inx) => {
          if (item && index == inx) {
            isChecked[pp] = this.boxForm[pp];
          }
        });
      });
      if (this.checkList.check6) {
        isChecked["06010008"] = this.boxForm["06010008"];
      }

      if (this.activeName == "first" && Object.keys(isChecked).length == 0) {
        this.$message.error("请勾选需要设置的参数！");
        return;
      } else if (
        this.activeName == "first" &&
        !Object.values(isChecked).every((item) => item || item == "0")
      ) {
        this.$message.error("请设置已勾选的参数值！");
        return;
      } else if (
        this.activeName == "first" &&
        (!this.operateRule.count || !this.operateRule.interval)
      ) {
        this.$message.error("请输入个数及间隔！");
        return;
      } else if (this.activeName == "first") {
        handleConfirm("确定要批量设置参数吗？", "warning", "提示")
          .then((res) => {
            this.paramsSetting(isChecked);
          })
          .catch((err) => {});
      } else if (this.activeName == "fourth") {
        this.submitForm("operateForm");
      }
    },
    paramsSetting(isChecked) {
      let datas = [];
      for (const key in isChecked) {
        datas.push({
          id: key,
          value: isChecked[key],
        });
      }
      let batchSearchForm = { ...this.batchSearchForm };
      delete batchSearchForm.pageNum;
      delete batchSearchForm.pageSize;
      let params = {
        queryParam: batchSearchForm,
        param: datas,
        operateRule: this.operateRule,
      };
      equipment("/operate/param/batch/insert/async", "post", params, 1).then(
        (res) => {
          if (res.code == 200) {
            this.$message.success(res.message);
            this.resetData();
            this.$emit("cancelDialog",1);
          }
        }
      );
    },
    resetData() {
      for (const key in this.boxForm) {
        this.boxForm[key] = undefined;
      }
      for (const key in this.checkList) {
        this.checkList[key] = false;
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          handleConfirm("确定要设置运营平台链接参数吗？", "warning", "提示")
            .then((res) => {
              this.runParamSet();
            })
            .catch((err) => {});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    runParamSet() {
      let { count, interval } = this.operateForm;
      let {
        deviceName,
        deviceSecret,
        password,
        port,
        productKey,
        url,
        username,
      } = this.operateForm;
      let batchSearchForm = { ...this.batchSearchForm };
      delete batchSearchForm.pageNum;
      delete batchSearchForm.pageSize;
      let params = {
        queryParam: batchSearchForm,
        param: {
          deviceName,
          deviceSecret,
          password,
          port,
          productKey,
          url,
          username,
        },
        operateRule: { count, interval },
      };
      equipment(
        "/operate/control/connectionparam/batch/insert/async",
        "post",
        params,
        1
      ).then((res) => {
        if (res.code == 200) {
          this.$message.success(res.message);
          this.resetOperateData();
          this.$emit("cancelDialog",1);
        }
      });
    },
    resetOperateData() {
      this.operateForm = {
        deviceName: "",
        deviceSecret: "",
        password: "",
        port: "",
        productKey: "",
        url: "",
        username: "",
        count: 30,
        interval: 1,
      };
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/common.scss";
.el-card__body {
  @include flexLayout(center, flex-start);
}
</style>
<style scoped lang="scss">
@import "@/styles/common.scss";

.boxForm {
  @include flexLayout(center, flex-start);
  flex-wrap: wrap;
  .single {
    position: relative;
    width: 33%;
    margin-bottom: 5px;
    @include flexLayout(center, space-between);
    .el-form-item {
      margin: 0 0 0 4%;
    }
    .el-checkbox {
      position: absolute;
      left: 0%;
      ::v-deep .el-checkbox__inner{
        border-color:#5473E8;
      }
    }
    .forbidden {
      color: red;
      margin-left: 6px;
    }
    .enable {
      color: #409eff;
      margin-left: 6px;
    }
  }
}
.operateForm,
.binForm {
  @include flexLayout(center, flex-start);
  flex-wrap: wrap;
  .el-form-item {
    width: 50%;
  }
}
.operateForm{

  .el-form-item{
    width: 33%;
    margin-bottom:16px;
    .el-input{
      width: 200px;
    }
  }
}
.input-width {
  width: 200px;
}
.batch-param {
  min-height: 120px;
  max-height: 80vh;
  position: relative;
  padding: 0 0 0 10px;
  overflow-y: auto;
  .tip-btn {
    position: absolute;
    top: 0;
    right: 0;
  }
}
.batch_btn {
  margin-left: 10px;
}
::v-deep .el-input.is-disabled .el-input__inner {
  color: #000000;
}
.rules{
  ::v-deep .el-card__body{
  @include flexLayout(center, flex-start);}
  .el-form-item{
    width:auto;
    margin-bottom:0;
  }
}
</style>